package com.logistics.role.controller;

import com.logistics.role.entity.model.RolePager;
import com.logistics.role.entity.model.RoleSave;
import com.logistics.role.service.RoleService;
import com.logistics.utils.aspect.annotation.LoggerListener;
import com.logistics.utils.constants.LoggerMethod;
import com.logistics.utils.exception.MessageException;
import com.logistics.utils.response.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("sys/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    /**
     * 查找角色
     * @param param
     * @return
     */
    @PostMapping("pager")
    @LoggerListener(businessName = "分页查询角色", methodName = LoggerMethod.SEARCH)
    public ResponseEntity pager(@RequestBody RolePager param){
        return ResponseUtil.success(roleService.pager(param));
    }

    /**
     * 查找所有的角色
     * @return
     */
    @GetMapping("listAll")
    @LoggerListener(businessName = "查询所有角色", methodName = LoggerMethod.SEARCH)
    public ResponseEntity listAll(){
        return ResponseUtil.success(roleService.listAll());
    }

    /**
     * 保存
     * @param save
     * @return
     */
    @PutMapping("save")
    @LoggerListener(businessName = "保存角色信息", methodName = LoggerMethod.SAVE)
    public ResponseEntity save(@RequestBody RoleSave save) throws MessageException {
        roleService.save(save);
        return ResponseUtil.success();
    }

    /**
     * 查找详细
     * @param id
     * @return
     * @throws MessageException
     */
    @GetMapping("details/{id}")
    @LoggerListener(businessName = "查询角色详细", methodName = LoggerMethod.SEARCH)
    public ResponseEntity details(@PathVariable("id") String id) throws MessageException {
        return ResponseUtil.success(roleService.details(id));
    }

    /**
     * 删除角色
     * @param ids
     * @return
     * @throws MessageException
     */
    @DeleteMapping("/remove/{ids}")
    @LoggerListener(businessName = "删除角色信息", methodName = LoggerMethod.DELETE)
    public ResponseEntity remove(@PathVariable("ids") String ids) throws MessageException {
        roleService.delete(ids);
        return ResponseUtil.success();
    }
}
